package com.tony.jdbc.dynamic.config;

import com.tony.jdbc.dynamic.interceptor.DynamicDatasourceInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author tony
 * @desc 添加web全局动态数据源注解拦截，只拦截Controller方法或类注解。
 * 如果需要同时拦截Service和Controller使用DynamicDatasourceAspect，不使用WebMvcConfig
 * @date 2025/11/12 08:51
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new DynamicDatasourceInterceptor())
                .addPathPatterns("/**"); // 拦截所有Controller路径
    }
}